package com.yc.system.security.controller;

import com.yc.framework.baseClass.R;
import com.yc.framework.utils.MailManager;
import com.yc.framework.utils.RedisUtils;
import com.yc.framework.utils.ResultUtil;
import com.yc.framework.utils.SaltUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 初始页面
 * @author zwq
 * @date 2020-04-04
 **/
@RestController
@RequestMapping("/index")
public class IndexController {

    @Autowired
    public RedisUtils redisUtils;

    /**
     * 首页
     * @author zwq
     * @date 2020/4/4
     * @return
     **/
    @RequestMapping(value = "/info",method = RequestMethod.GET)
    public Map<String,Object> userLogin(){
        // 组装参数
        Map<String,Object> result = new HashMap<>();
        result.put("title","这里是首页不需要权限和登录拦截");
        return ResultUtil.resultSuccess(result);
    }

    //发送验证码
    @Autowired
    MailManager mailManager;

    @GetMapping("/sendMailTest")
    R sendMailTest(@RequestParam("email") String email) {
        String salt=SaltUtils.getSalt(4);
        redisUtils.setEx(email,salt,5*60L);
        mailManager.sendHtmlMail("校园二手书", "<h2>欢迎注册校园二手书。<h2><h1>验证码为："+salt+"</h1><h2>5分钟内有效<h2>", email);
        //最后是收件人列表
       return R.ok();
    }
}

